/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.tests;

import java.util.Arrays;

import org.antlr.runtime.RecognitionException;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

import ac.jp.u_tokyo.SyncLib.Mod;
import ac.jp.u_tokyo.SyncLib.SynchronizationFailedException;
import ac.jp.u_tokyo.SyncLib.language3.FindBy;
import ac.jp.u_tokyo.SyncLib.language3.GlobalIncrementalFactory;
import ac.jp.u_tokyo.SyncLib.modParser.ModParser;
import ac.jp.u_tokyo.SyncLib.util.Helper;
import ac.jp.u_tokyo.SyncLib.valueParser.ValueParser;

public class FindByResyncTest extends SyncTestBase
{
	
	FindBy sync;
	
	@Before
	public void setUp() throws SynchronizationFailedException, RecognitionException {
		sync = new FindBy();
		sync.setAttributeName("a");
		GlobalIncrementalFactory.reset();
	}
	
	@Test
	public void testNullValue() throws SynchronizationFailedException, RecognitionException {
		Object[] objs = ValueParser.parse("{0->{a->x}, 1->{a->y}}, null, 1");
		Mod[] result = sync.resynchronize(objs, ModParser.parse("void, void, 1"));
		Helper.applyMods(objs, result);
		assertArrayEquals(ValueParser.parse("{0->{a->x}, 1->{a->y}}, y, 1"), objs);
	}
	
//	@Test
//	public void testAllNull() throws SynchronizationFailedException, RecognitionException {
//		Object[] objs = ValueParser.parse("null, null, null");
//		Mod[] result = sync.resynchronize(objs, ModParser.parse("void, void, void"));
//		Helper.applyMods(objs, result);
//		assertArrayEquals(ValueParser.parse("{1->{}}, null, 1"), objs);
//	}
	
	@Test(expected=SynchronizationFailedException.class)
	public void testNullKey() throws SynchronizationFailedException, RecognitionException {
		Object[] objs = ValueParser.parse("null, null, null");
		sync.resynchronize(objs, ModParser.parse("void, void, null"));
	}


}
